<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>忘记密码 - layuiAdmin</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
  <link rel="stylesheet" href="../../layuiadmin/style/login.css" media="all">
</head>

  <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
      <div class="layadmin-user-login-box layadmin-user-login-header">
        <h2>layuiAdmin</h2>
        <p>layui 官方出品的单页面后台管理模板系统</p>
      </div>
      <div id="content" class="layadmin-user-login-box layadmin-user-login-body layui-form">
        <!--重置密码-->
        <div id="updatePwdDiv" hidden>
            <div class="layui-form-item">
              <label class="layadmin-user-login-icon layui-icon layui-icon-password" ></label>
              <input type="password" id="password" placeholder="密码，6-20为数字字母组合" class="layui-input" @blur="checkPwd()">
              <span id="checkPwd" style="color: red"></span>
            </div>
            <div class="layui-form-item">
              <label class="layadmin-user-login-icon layui-icon layui-icon-password"></label>
              <input type="password" id="repass" placeholder="确认密码，6-20为数字字母组合" class="layui-input">
              <span id="checkRepwd" style="color: red"></span>
            </div>
            <div class="layui-form-item">
              <input type="button" class="layui-btn layui-btn-fluid" value="重置新密码" @click="updatePwd()">
            </div>
        </div>
          <!--获取验证码-->
        <div id="checkVercodeDidv">
          <div class="layui-form-item">
            <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone"></label>
            <input name="tel" placeholder="请输入手机号" class="layui-input" v-model="tel">
            <span id="checkTel" style="color: red"></span>
          </div>
            <div class="layui-form-item">
              <div class="layui-row">
                <div class="layui-col-xs7">
                  <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"></label>
                  <input id="vercode" placeholder="短信验证码" class="layui-input">
                </div>
                <div class="layui-col-xs5">
                  <div style="margin-left: 10px;">
                    <input type="button" id="sendVercode" class="layui-btn layui-btn-primary layui-btn-fluid" value="获取验证码" @click="sendVercode($event)">
                  </div>
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <span id="checkVercode" style="color: red"></span>
              <input type="button" class="layui-btn layui-btn-fluid" value="找回密码" @click="checkVercode()">
            </div>
        </div>
      </div>
    </div>

  </div>
<script type="text/javascript" src="/houtai/js/jquery-2.1.4.js"></script>
<script src="/houtai/js/vue.js"></script>
<script src="../../layuiadmin/layui/layui.js"></script>
<script>
  var vue = new Vue({
      el:"#content",
      data:{
          tel:""
      },
      methods:{
          sendVercode:function (e) {
              var _this = this;
              var tel = _this.tel;
              var pattern = /^1[3456789]\d{9}$/;
              if(pattern.test(tel)){
                  console.log(tel);
                  $.ajax({
                      url:"/houtai/adminuser/sendVercode",
                      data:{tel:tel},
                      type:"post"
                  });
                  $("#checkTel").text("");
                  var time = 180;
                  var timer = setInterval(function(){
                      time--;
                      $("#sendVercode").val("（"+time+"秒）重发");
                      $("#sendVercode").prop("disabled",true);
                      if(time==0){
                          clearInterval(timer);
                          $("#sendVercode").val("获取验证码");
                          $("#sendVercode").prop("disabled",false);
                      }
                  },1000);
              }else{
                $("#checkTel").text("请输入正确手机号")
              }
          },
          checkVercode:function () {
            var _this = this;
            var vercode = $("#vercode").val();
            console.log(vercode);
            if(vercode != null && vercode.trim() != ''){
              $.ajax({
                  url:"/houtai/adminuser/checkVercode",
                  data:{tel:_this.tel,vercode:vercode},
                  type:"post",
                  dataType:"json",
                  success:function (data) {
                      console.log(data);
                      if(data.message == "success"){
                          $("#checkVercode").text("");
                          $("#checkVercodeDidv").prop("hidden",true);
                          $("#updatePwdDiv").prop("hidden",false);
                      }else{
                          $("#checkVercode").text("验证码错误");
                      }
                  }
              })
            }
          },
          updatePwd:function () {
              var pwd = $("#password").val();
              var repwd = $("#repass").val();
              var _this = this;
              console.log(_this.tel);
              if(this.checkPwd() && pwd == repwd){
                  $.ajax({
                      url:"/houtai/adminuser/updatepwd",
                      data:{pwd:repwd,tel:_this.tel},
                      type:"post",
                      dataType:"json",
                      success:function (data) {
                          if(data.message == "success"){
                              alert("修改成功");
                              location.href = "login.html";
                          }else{
                              alert("修改失败");
                          }
                      }
                  })
              }
          },
          checkPwd:function () {
              var pwd = $("#password").val();
              var pattern = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;
              if (!pattern.test(pwd)){
                  console.log("密码不合法")
                return false;
              }else{
                  $("#checkPwd").text("");
                  return true;
              }
          }
      }
  })
</script>
</body>
</html>